import check from '@/common/check.js'
export default {
	//获取运单号
	getWaybillGoodSn(inputData) {
		var today = new Date();
		var month = today.getMonth() + 1;
		var day = today.getDate();
		if (check.isNull(inputData.waybill_sn)) {
			return '';
		}
		return month + '' + day + "-" +
			inputData.waybill_sn.substr(-5, 5) + "-" +
			("00" + inputData.goods.length).substr(-2, 2);
	},

	packPickerChange(e, r, lists, inputData) {
		var goodsItem = lists[e.detail.value];
		inputData.goods[r].goods_pack = goodsItem.name;
	},

	payPickerChange(e, lists, inputData) {
		var payItem = lists[e.detail.value];
		inputData.order_amount_pay = payItem.type;
		inputData.order_amount_pay_name = payItem.name;
	},

	deliveryPickerChange(e, lists, inputData) {
		var deliveryItem = lists[e.detail.value];
		inputData.delivery_type = deliveryItem.type;
		inputData.delivery_type_name = deliveryItem.name;
	},

	receiptPickerChange(e, lists, inputData) {
		var item = lists[e.detail.value];
		inputData.receipt_type = item.type;
		inputData.receipt_type_name = item.name;
	},
	switchReceiptChange(e, inputData) {
		if (e) {
			inputData.is_receipt = 2;
			inputData.receipt_type = '1';
			inputData.receipt_type_name = '托运单签名盖章返回';
			inputData.receipt_num = '1';
		} else {
			inputData.is_receipt = 1
			inputData.receipt_type = '';
			inputData.receipt_type_name = '';
			inputData.receipt_num = '';
		}
		console.log(inputData)
	},
	receiptWatch(val, inputData) {
		if (inputData.order_amount_pay == "30" && Number(inputData.order_amount) > 0) {
			this.switchReceiptChange(true, inputData);
		} else {
			this.switchReceiptChange(false, inputData);
		}
	},
	switchUnusualChange(e, inputData) {
		inputData.is_unusual = e.detail.value ? 2 : 1
	},
	switchUrgencyChange(e, inputData) {
		inputData.is_urgency = e.detail.value ? 2 : 1
	},

	handleParamsData(inputData) {
		inputData.order_amount = check.strNullReplace(inputData.order_amount, '0');
		inputData.delivery_fee = check.strNullReplace(inputData.delivery_fee, '0');
		inputData.pickup_fee = check.strNullReplace(inputData.pickup_fee, '0');
		inputData.insurance_fee = check.strNullReplace(inputData.insurance_fee, '0');
		inputData.information_fee = check.strNullReplace(inputData.information_fee, '0');
		inputData.advance_amount = check.strNullReplace(inputData.advance_amount, '0');
		inputData.transit_fee = check.strNullReplace(inputData.transit_fee, '0');
	},

	all_order_amount(inputData) { //总费用（总运费）
		this.handleParamsData(inputData);
		var money = inputData.order_amount * 1 + //运费
			inputData.pickup_fee * 1 + //上门取货费
			inputData.delivery_fee * 1 + //送货费
			inputData.information_fee * 1 + //信息费
			inputData.transit_fee * 1 + //中转费
			inputData.insurance_fee * 1 + //保价费
			inputData.advance_amount * 1;
		return (money).toFixed(2); //代收货款
	},
	carry_order_amount(inputData) { //提付合计
		this.handleParamsData(inputData);
		return (
			(inputData.order_amount_pay == "20" ? inputData.order_amount * 1 : 0) + //运费
			(inputData.delivery_fee_pay == "20" ? inputData.delivery_fee * 1 : 0) + //送货费
			(inputData.pickup_fee_pay == "20" ? inputData.pickup_fee * 1 : 0) + //上门取货费
			(inputData.transit_fee_pay == "20" ? inputData.transit_fee * 1 : 0)
		).toFixed(2); //中转费
	},
	now_order_amount(inputData) {
		this.handleParamsData(inputData);
		return (
			(inputData.order_amount_pay == "10" ? inputData.order_amount * 1 : 0) + //运费
			(inputData.pickup_fee_pay == "10" ? inputData.pickup_fee * 1 : 0) + //上门取货费
			(inputData.delivery_fee_pay == "10" ? inputData.delivery_fee * 1 : 0) + //送货费
			(inputData.transit_fee_pay == "10" ? inputData.transit_fee * 1 : 0)
		).toFixed(2); //中转费
	}, //现付合计
	get_advance_amount(inputData){
		return check.strNullReplace(inputData.advance_amount, '0');
	},
};